package il.ac.bgu.cs.heuristics.core;

import il.ac.bgu.cs.heuristics.core.caching.ICachingEngine;
import il.ac.bgu.cs.heuristics.graph.types.IState;
import il.ac.bgu.cs.heuristics.utils.Pair;

public class HeuristicImpProxy implements IHeuristicsEngine {

	IHeuristicsEngine				m_heuristicsEngine;
	ICachingEngine<Pair<IState>>	m_cache;

	public HeuristicImpProxy(IHeuristicsEngine engine,
			ICachingEngine<Pair<IState>> cache) {
		m_heuristicsEngine = engine;
		this.m_cache = cache;
	}

	@Override
	public int getHValue(IState init, IState goal) {
		Pair<IState> initGoalPair = new Pair<IState>(init, goal);
		Integer integerHValue = m_cache.get(initGoalPair);
		if (integerHValue != null) {
			return integerHValue.intValue();
		} else {
			int hValue = m_heuristicsEngine.getHValue(init, goal);
			m_cache.put(initGoalPair, Integer.valueOf(hValue));
			return hValue;
		}
	}

	@Override
	public String getStatisticString() {
		// TODO Auto-generated method stub
		return "";
	}

}
